<?php
require('SalidaEntradaProducto.class.php');

$modo = (isset($_GET['modo'])) ? $_GET['modo']:0;
switch($modo){
    case 1: //Consultar Grid
        if(isset($_GET['modo']) == 1){
            $tipoProducto   = $_GET['tipoProducto'];
            $page           = $_POST['page'];
            $rp             = $_POST['rp'];
            $sortname       = $_POST['sortname'];
            $sortorder      = $_POST['sortorder'];
            $query          = $_POST['query'];
            $letter_pressed = isset($_POST['letter_pressed'])?$_POST['letter_pressed']:null;
            $qtype          = $_POST['qtype'];
            $obj            = new SalidaEntradaProducto();
            $obj->consultar_grid($page, $rp, $sortname, $sortorder, $query, $letter_pressed, $qtype, $tipoProducto);
        }
        break;
    case 2: //Insertar Salida del Producto
        if(isset($_POST['submit'])){
            $tipoProducto   = $_GET['tipoProducto'];
            $id             = $_POST['id'];
            $cant           = trim($_POST['cant']);
            $usuId          = $_POST['usuId'];
            $fecAct         = date("Ymd");
            $horAct         = date("His");
            
            $array[0]       = $id;
            $array[1]       = $cant;
            $array[2]       = $fecAct;
            $array[3]       = $horAct;
            $array[4]       = $usuId;
            
            $obj        = new SalidaEntradaProducto();
            $result     = false;
            if($tipoProducto == 1){
                $result = $obj->insertarSalida($array);
            }else if($tipoProducto == 2){
                $result = $obj->insertarEntrada($array);
            }
            if ( $result == true) echo 1;
            else  echo 0;            
        }
        break;
    default:
        echo "Debe seleccionar un modo: \n1. Consultar Grid\n2. Insertar\n3. Modificar\n4. Eliminar";
}

?>
